package com.ly.spring.jdbc.dao;

import com.ly.spring.jdbc.entity.Oprecored;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/11/11
 * Email haijunzhou@hnit.edu.cn
 */

@Repository
public class OprecordDao {

    @Autowired
    JdbcTemplate jdbcTemplate;

    // 查询用户的全部流水记录
    public Oprecored queryByAid(long aid){
        String sql = "select * from bank_oprecord where aid = ?";
        return jdbcTemplate.queryForObject(sql,
                new BeanPropertyRowMapper<Oprecored>(Oprecored.class),aid);
    }

    // 新增用户流水(存款,取款,转账...)
    public void insert(Oprecored oprecored){
        String sql = "insert into bank_oprecord values (default,?,?,?,now(),?)";
        jdbcTemplate.update(sql, oprecored.getAid(),
                oprecored.getOpmoney(),
                oprecored.getCharge(),
                oprecored.getRemark());
    }
}
